package com.model.indent;

import java.util.List;

import com.dao.IndentDao;

/**
 * 订单业务层
 * @author 飘仙人
 *
 */
public class IndentManager {
	IndentDao indentdao = new IndentDao();

	/**
	 * 查询所有订单
	 * @return
	 */
	public List<Indent> findAll(){
		List<Indent> IndentList = null;
		try{
			IndentList = indentdao.findAll();		
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return IndentList;
	}
	
	/**
	 * 查询一个订单
	 * @param Actionid
	 * @return
	 */
	public Indent findById(Long Actionid){
		Indent indent = null;
		try{
			indent = indentdao.findById(Actionid);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return indent;
	}
	
	/***
	 * 立刻购买 
	 * @param goodId
	 * @param userId
	 * @param num
	 * @return
	 */
	public boolean buyGoods(long goodId,long userId,int num){
		boolean bFlag = false;
		try{		
			int iFlag = indentdao.buyGoods(goodId, userId, num);
			bFlag = iFlag>0?true:false;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return bFlag;
	}
	
	/**
	 *  查询订单
	 * @param username
	 * @return
	 */
	public List<Indent> findAllIndent(String username){
		List<Indent> IndentList = null;
		try{
			IndentList = indentdao.findAllIndent(username);	
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return IndentList;
	}
	
	/**
	 * 修改订单状态
	 * @param state
	 * @param actionid
	 * @return
	 */
	public boolean upIndent(String state, long actionid){
		boolean bFlag = false;
		try{		
			int iFlag = indentdao.upIndent(state, actionid);
			bFlag = iFlag>0?true:false;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return bFlag;
	}
}
